/*
 * bot.h
 *
 *  Created on: Nov 27, 2013
 *      Author: killerg
 */

#ifndef BOT_H_
#define BOT_H_

#include "share/net_c.h"

struct account_t {
    int32_t id = -1;
    std::string account = "";
    std::string passwd = "";
};

struct arg_t {
    std::string logon_addr;
    event_base* base;

    int min_interval;
    int max_interval;
    int min_packet;
    int max_packet;
    int min_play_sec;
    int max_play_sec;

    arg_t() {

        logon_addr = "";
        base = NULL;

        min_interval = 100;
        max_interval = 1000;
        min_packet = 10;
        max_packet = 400;
        min_play_sec = 36000000;
        max_play_sec = 36000000;
    }
};

struct data_t {
    std::string server_addr;
    int64_t playerid;
    int32_t key;
    data_t() {
        server_addr = "";
        playerid = -1;
        key = -1;
    }
};

struct echo_static_t {
    double latency_min;
    double latency_max;
    double latency_all;
    double play_timer;
    int num;

    echo_static_t() {
        reset();
    }
    void reset() {
        latency_min = 99999.0f;
        latency_max = 0;
        latency_all = 0;
        play_timer = 0;
        num = 0;
    }

    std::string get_str();
};

enum EServerStage {
    EErrorLogon         = 0 ,
    EErrorServer        = 1 ,
    EIdle               = 2 ,
    ELogonInit          = 3 ,
    ELogonConnecting    = 4 ,
    ELogonAuthing       = 5 ,
    ELogonRegistering   = 6 ,
    ELogonGettingList   = 7 ,
    ELogonSelecting     = 8 ,
    EServerInit         = 9 ,
    EServerConnecting   = 10,
    EServerLoading      = 11,
    EServerCreating     = 12,
    EServerPlaying      = 13,
};

extern const char* ServerStageName[];

const int ESSTAGENUM = EServerPlaying+1;

struct bot_t {
	account_t* account = NULL;
	int64_t machinecode = -1;
    tran_c net;
    arg_t arg;
    data_t data;
    EServerStage stage;
    echo_static_t stat;

    bool init(const arg_t &arg);
    void destroy();
    void update();

    void update_lmsg();
    void update_smsg();

    double echo_timer;
    double mail_timer;
    int mailindex;
    double try_interval;
    double play_timer;

};

#endif /* BOT_H_ */
